window.onload=function(){
    selectGoods();
    function selectGoods() {
        $.ajax({
            type:'post',
            dataType:"json",
            url:"/order/selectGoodsStatistics",
            data:{"orderType":2},
            success:function (data) {
                var type = new Array();
                var count = new Array();
                var list = data.data;
                $("#title").empty();
                $("#sum").empty();
                $("#title").append("<td>商品类型</td>");
                $("#sum").append("<td>订单次数</td>");
                for (var i = 0;i<list.length;i++){
                    $("#title").append("<td>"+list[i].title+"</td>");
                    $("#sum").append("<td>"+list[i].countNum+"</td>");
                    count.push(list[i].countNum);
                    type.push(list[i].title);
                }
                echart(type,count,"订单")
            }
        });
    };

    $("#goods").click(function () {
        selectGoods();
    });
    $("#curriculum").click(function () {
        $.ajax({
            type:'post',
            dataType:"json",
            url:"/order/selectCurriculumStatistics",
            data:{orderType:3},
            success:function (data) {
                console.log(data);
                var type = new Array();
                var count = new Array();
                var list = data.data;
                $("#title").empty();
                $("#sum").empty();
                $("#title").append("<td>课程类型</td>");
                $("#sum").append("<td>订单次数</td>");
                for (var i = 0;i<list.length;i++){
                    $("#title").append("<td>"+list[i].title+"</td>");
                    $("#sum").append("<td>"+list[i].collectNum+"</td>");
                    count.push(list[i].collectNum);
                    type.push(list[i].title);
                }
                echart(type,count,"订单");
            }
        });
    });

    var myChar = echarts.init(document.getElementById('main'));
    function echart(type,count,name) {
        var option = {
            title: {
                text: '订单统计图',
                subtext: '思云产品'
            },
            legend: {
                show: true
            },
            //y轴
            yAxis: {
                type: 'value',
                position: 'left',
            },
            xAxis:{
                data:type
            },
            series: [
                {
                    name: name,
                    type: 'bar',
                    data: count,
                    markPoint: {
                        data: [
                            { type: 'max', name: 'Max'},
                            { type: 'min', name: 'Min'}
                        ]
                    }
                }
            ]
        }
        myChar.setOption(option);
    };
}
